package com.example.demo.Util;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


;

@Component
public class HutoolNetWorkUtil {

    private static HutoolNetWorkUtil hutoolNetWorkUtil = null;

    private HutoolNetWorkUtil() {
        hutoolNetWorkUtil = this;
    }


    public static final String SYSTEM_WMS = "WMS";

    public static final String SYSTEM_FINANCE = "财务";


    public static String hutoolGet(String url) {
        String getResult = HttpUtil
                .createGet(url)
                .execute()
                .charset("UTF-8")
                .body();
//        }
        return getResult;
    }

    public static <T> String hutoolPost(T t, String url, String flag, String system) {
        JSONObject jsonObject = JSONUtil.parseObj(t);
//        InterfaceLog interfaceLog = new InterfaceLog();
//        interfaceLog.setCallTime(new Date());
        String postResult = HttpRequest
                .post(url)
                .header("Content-Type", "application/json")
                .body(String.valueOf(jsonObject))
                .execute()
                .body();

        if (ObjectUtil.isNotEmpty(flag) && "1".equals(flag)) {
            HutoolNetWorkUtil hutoolNetWorkUtil =new HutoolNetWorkUtil();
        }
        return postResult;
    }

    public static String hutoolPostArrayJson(Object t, String url, String flag, String system) {
//        InterfaceLog interfaceLog = new InterfaceLog();
//        interfaceLog.setCallTime(new Date());
        String postResult = HttpRequest
                .post(url)
                .header("Content-Type", "application/json")
                .body(JSONUtil.toJsonStr(t))
                .execute()
                .body();

//        if(ObjectUtil.isNotEmpty(flag) && "1".equals(flag)) {
//            netWorkService.saveLogUtf8(interfaceLog, url, system, t, postResult);
//        }
        return postResult;
    }

}
